Skip to content

[CMake] Make link-time optimization of the python modules optional - #651

Open
fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:make_lto_optional
Open

fredroy wants to merge 1 commit into
sofa-framework:masterfrom
fredroy:make_lto_optional

Conversation

@fredroy

@fredroy fredroy commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

SP3_add_python_module always linked pybind11::lto, so every python module was built with LTO in Release and MinSizeRel builds.

Add the option SP3_ENABLE_LINK_TIME_OPTIMIZATION, OFF by default like SOFA's SOFA_ENABLE_LINK_TIME_OPTIMIZATION, and warn when it is ON in Debug or RelWithDebInfo builds, where pybind11 ignores it.

Only link pybind11::lto when the target exists: pybind11 does not create it when CMAKE_INTERPROCEDURAL_OPTIMIZATION is set, which made the configure fail.


for in-tree compilation, LTO will be set in any case if SOFA's one is set (propagated from Sofa.Config)

So, for LTO state:
if SOFA off and SP3 off -> no LTO
if SOFA on and SP3 off -> LTO (all)
if SOFA on and SP3 on -> LTO (all)
if SOFA off and SP3 on -> LTO (only SP3)

for out of tree, only SP3_ENABLE_LINK_TIME_OPTIMIZATION is taken into account.

SP3_add_python_module always linked pybind11::lto, so every python module
was built with LTO in Release and MinSizeRel builds.

Add the option SP3_ENABLE_LINK_TIME_OPTIMIZATION, OFF by default like SOFA's
SOFA_ENABLE_LINK_TIME_OPTIMIZATION, and warn when it is ON in Debug or
RelWithDebInfo builds, where pybind11 ignores it.

Only link pybind11::lto when the target exists: pybind11 does not create it
when CMAKE_INTERPROCEDURAL_OPTIMIZATION is set, which made the configure fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant